package org.devops

// 代码扫描
def SonarScan(projectName,projectDesc,projectPath){
    withSonarQubeEnv(credentialsId: 'sonarqube') {
        // sonarScanner安装地址
        def sonarHome = "/opt/sonar-scanner-4.3.0.2102-linux"
        // 以时间戳为版本
        def scanTime = sh returnStdout: true, script: 'date +%Y%m%d%H%m%S'
        scanTime = scanTime - "\n"
        sh """
        ${sonarHome}/bin/sonar-scanner  \
        -Dsonar.projectKey=${projectName}  \
        -Dsonar.projectName=${projectName}  \
        -Dsonar.projectVersion=${scanTime} \
        -Dsonar.ws.timeout=30 \
        -Dsonar.projectDescription="${projectDesc}"  \
        -Dsonar.links.homepage=http://www.baidu.com \
        -Dsonar.sources=${projectPath} \
        -Dsonar.sourceEncoding=UTF-8 \
        -Dsonar.java.binaries=target/classes \
        -Dsonar.java.test.binaries=target/test-classes \
        -Dsonar.java.surefire.report=target/surefire-reports

        echo "${projectName}  scan success!"
        """
    }
}